package net.biancheng.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.biancheng.common.annotation.Log;
import net.biancheng.common.core.BaseController;
import net.biancheng.common.core.CommonResult;
import net.biancheng.common.enums.BusinessType;
import net.biancheng.bean.SysDictType;
import net.biancheng.service.ISysDictTypeService;
import net.biancheng.common.core.page.TableDataInfo;

/**
 * 字典类型Controller
 * 
 * @author lb
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/system/dict/type")
public class SysDictTypeController extends BaseController
{
    @Autowired
    private ISysDictTypeService sysDictTypeService;

    /**
     * 查询字典类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDictType sysDictType)
    {
        startPage();
        List<SysDictType> list = sysDictTypeService.selectSysDictTypeList(sysDictType);
        return getDataTable(list);
    }

    /**
     * 获取所有字典类型下拉选择列表
     */
    @GetMapping("/listAll")
    public CommonResult getAllList() {
        return CommonResult.success(sysDictTypeService.selectSysDictTypeAllList());
    }

    /**
     * 获取字典类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable Long id)
    {
        return CommonResult.success(sysDictTypeService.selectSysDictTypeById(id));
    }

    /**
     * 新增字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:dict:add')")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody SysDictType sysDictType)
    {
        return toResult(sysDictTypeService.insertSysDictType(sysDictType));
    }

    /**
     * 修改字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
    @Log(title = "字典类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody SysDictType sysDictType)
    {
        return toResult(sysDictTypeService.updateSysDictType(sysDictType));
    }

    /**
     * 删除字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toResult(sysDictTypeService.deleteSysDictTypeByIds(ids));
    }
}
